package com.mediacloud.app.newsmodule.fragment.baoliao.frag;

import android.Manifest;
import android.app.Dialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.fastjson.JSON;
import com.lzf.easyfloat.utils.DisplayUtils;
import com.mediacloud.app.assembly.widget.media.IMediaStateListener;
import com.mediacloud.app.assembly.widget.media.MediaProxy;
import com.mediacloud.app.model.OnPauseBaoliaoViedeoList;
import com.mediacloud.app.model.eventbus.event.LoginEvent;
import com.mediacloud.app.model.interfaces.DataInvokeCallBack;
import com.mediacloud.app.model.news.ArticleItem;
import com.mediacloud.app.model.news.ArticleListDataWithAdv;
import com.mediacloud.app.model.utils.LogUtil;
import com.mediacloud.app.model.utils.TimeUtils;
import com.mediacloud.app.model.utils.ViewUtils;
import com.mediacloud.app.model.view.floatwin.FloatButtonGroup;
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.activity.microlive.BaseRecyclerAdapter;
import com.mediacloud.app.newsmodule.activity.microlive.BaseRecyclerAdapterX;
import com.mediacloud.app.newsmodule.fragment.SimpleBottomSheetDialog;
import com.mediacloud.app.newsmodule.fragment.baoliao.activity.BaoLiaoDetailActivity;
import com.mediacloud.app.newsmodule.fragment.baoliao.adapter.BaoLiaoNavListAdapter;
import com.mediacloud.app.newsmodule.fragment.baoliao.api.FacadeApi;
import com.mediacloud.app.newsmodule.fragment.baoliao.api.MemberApi;
import com.mediacloud.app.newsmodule.fragment.nav2.BaseRecyclerListFragment;
import com.mediacloud.app.newsmodule.model.AddHistoryParamsData;
import com.mediacloud.app.newsmodule.model.baoliao.list.list.BaoNiaoListItem;
import com.mediacloud.app.newsmodule.utils.BaoLiaoBlockListUtils;
import com.mediacloud.app.newsmodule.utils.BaoLiaoItemMoreHandler;
import com.mediacloud.app.newsmodule.utils.BindEventBus;
import com.mediacloud.app.newsmodule.utils.HistoryInvoker;
import com.mediacloud.app.newsmodule.utils.LoginUtils;
import com.mediacloud.app.newsmodule.utils.NewsListDataInvoker;
import com.mediacloud.app.newsmodule.utils.ToastUtil;
import com.mediacloud.app.user.model.UserInfo;
import com.mediacloud.app.user.utils.RxUtils;
import com.scwang.smartrefresh.layout.api.RefreshLayout;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import xyz.doikki.videoplayer.player.VideoView;

/**
 * Created by Yoake on 2018/8/29.
 */
@SuppressWarnings("ALL")
public class BaoLiaoListFragment extends BaseRecyclerListFragment<BaoLiaoNavListAdapter> implements DataInvokeCallBack<ArticleListDataWithAdv>, BaseRecyclerAdapterX.ItemClickListener, SimpleBottomSheetDialog.ItemClickListener {
    protected NewsListDataInvoker newsListDataInvoker;
    private BaoLiaoNavListAdapter adapter;
    //仅仅刷新数据
    private boolean onlyRefresh = false;
    private AlertDialog mDialog;
    //    private SharedPreferencesCache mSp;
    private boolean isFirst = true;
    private MediaProxy mMediaPlayer;

    private String missionTitle = "";
    private long missionId = 0L;
    ConstraintLayout clockInLayout;
    ConstraintLayout clockedInLayout;
    TextView title;
    TextView time;
    TextView clockInDay;
    TextView clockInRank;
    private boolean choose = false;
    private String mediaInfo;
    private int mediaInfoType;
    private Dialog videoDialog;
    private View iamgeClose;
    private VideoView videoView;

    @Override
    public BaoLiaoNavListAdapter getRecyclerAdapter() {
        adapter = new BaoLiaoNavListAdapter(getActivity(), recyclerView);
        return adapter;
    }


    @Override
    public void choosed() {
        super.choosed();
        choose = true;
        if (choose && !isFirst) {
            getMissionList();
        }
    }

    @Override
    public void unChosoed() {
        super.unChosoed();
        choose = false;
    }

    @Override
    public void onResume() {
        super.onResume();
        recyclerAdapter.playResume();
        isFirst = false;
        if (choose) {
            getMissionList();
        }
    }

    private void clockIn() {
        UserInfo userInfo = UserInfo.getUserInfo(requireContext());
        JSONObject object = new JSONObject();
        try {
            object.put("memberId", userInfo.getUserid());
            object.put("missionId", missionId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(MediaType.parse("application/json"), object.toString());
        MemberApi.getMemberApi()
                .clockIn(body)
                .compose(RxUtils.schedulersTransformer())
                .subscribe(new Observer<JSONObject>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        getCompositeDisposable().add(d);
                    }

                    @Override
                    public void onNext(@NonNull JSONObject jsonObject) {
                        Log.e(TAG, "" + jsonObject);
                        ClockInData data = com.alibaba.fastjson.JSONObject.parseObject(jsonObject.toString(), ClockInData.class);
                        if (data.isSuccess()) {
                            if (mediaInfoType == 3) {//视频
                                videoDialog.show();
                                videoView.setUrl(mediaInfo);
                                videoView.start();
                                videoView.addOnStateChangeListener(new VideoView.OnStateChangeListener() {
                                    @Override
                                    public void onPlayerStateChanged(int playerState) {
                                        if (playerState == VideoView.STATE_PLAYBACK_COMPLETED) {
                                            videoView.release();
                                            videoDialog.dismiss();
                                        }
                                    }

                                    @Override
                                    public void onPlayStateChanged(int playState) {

                                    }
                                });

                                iamgeClose.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        videoView.release();
                                        videoDialog.dismiss();
                                    }
                                });
                            } else if (mediaInfoType == 2) {//音频
                                mMediaPlayer.start();
                            }
                            clockInDay.setText(data.getData().getAccumulate() + "");
                            clockInRank.setText(data.getData().getSequence() + "");
                            clockInLayout.setVisibility(View.GONE);
                            clockedInLayout.setVisibility(View.VISIBLE);
                        } else {
                            ToastUtil.show(requireContext(), data.getDescription());
                            mDialog.dismiss();
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        e.printStackTrace();
                        Log.e(TAG, "" + e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    //获取打卡任务
    private void getMissionList() {
        UserInfo userInfo = UserInfo.getUserInfo(requireContext());
        JSONObject object = new JSONObject();
        try {
            object.put("memberId", userInfo.getUserid());
            object.put("searchType", 1);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(MediaType.parse("application/json"), object.toString());

        MemberApi.getMemberApi()
                .clockList(body)
                .compose(RxUtils.schedulersTransformer())
                .subscribe(new Observer<JSONObject>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        getCompositeDisposable().add(d);
                    }

                    @Override
                    public void onNext(@NonNull JSONObject jsonObject) {
                        Log.e(TAG, "" + jsonObject);
                        MissionData data = com.alibaba.fastjson.JSONObject.parseObject(jsonObject.toString(), MissionData.class);
                        if (data.isSuccess() && data.getData().size() > 0) {
                            for (int i = 0; i < data.getData().size(); i++) {
                                MissionData.DataBean bean = data.getData().get(i);
                                mediaInfo = bean.getMediaInfo();
                                mediaInfoType = bean.getMediaInfoType();
                                if (TextUtils.isEmpty(mediaInfo)) {
                                    mediaInfo = "android.resource://" + requireContext().getPackageName() + "/" + R.raw.clock_in_audio;
                                    mediaInfoType = 2;
                                }
                                if (mediaInfoType == 2)//音频提前去设值
                                    mMediaPlayer.setDataSource(mediaInfo);
                                long startDate = TimeUtils.string2Millis(bean.getStartDate() + " " + bean.getClockinStartTime(), "yyyy-MM-dd HH:mm:ss");
                                long endDate = TimeUtils.string2Millis(bean.getEndDate() + " " + bean.getClockinEndTime(), "yyyy-MM-dd HH:mm:ss");
                                long currentDate = new Date().getTime();
                                // String hhmmss = TimeUtils.date2String(new Date(), "HH:mm:ss");
                                if (bean.getClockinFlag() == 0 && startDate <= currentDate && currentDate <= endDate) {//是否打过卡，并且在此时间段
//                                    int startTime = getSecond(bean.getClockinStartTime());
//                                    int endTime = getSecond(bean.getClockinEndTime());
//                                    int currentTime = getSecond(hhmmss);
//                                    if (startTime <= currentTime && currentTime <= endTime) {
                                    missionId = bean.getId();
                                    missionTitle = bean.getName();
                                    title.setText(bean.getName());
                                    time.setText(bean.getClockinStartTime());
                                    clockInLayout.setVisibility(View.VISIBLE);
                                    clockedInLayout.setVisibility(View.GONE);
                                    mDialog.show();
                                    return;
                                    // }
                                }
                            }
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        e.printStackTrace();
                        Log.e(TAG, "" + e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    private static int getSecond(@NonNull String time) {
        String[] date = time.split(":");
        int result = 0;
        for (int i = 0; i < date.length; i++) {
            switch (i) {
                case 0:
                    result += Integer.parseInt(date[0]) * 60 * 60;
                    break;
                case 1:
                    result += Integer.parseInt(date[1]) * 60;
                    break;
                case 2:
                    result += Integer.parseInt(date[2]);
                    break;
            }
        }
        return result;
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (hidden) {
            if (recyclerAdapter != null) {
                recyclerAdapter.stopPlay();
            }
        }
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (!isVisibleToUser) {
            if (recyclerAdapter != null) {
                recyclerAdapter.stopPlay();
            }
        }
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(requireActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
        } else {
            try {
                // mMediaPlayer = MediaPlayer.create(requireContext(), R.raw.clock_in_audio);
                mMediaPlayer = new MediaProxy(new AndroidKernel());
                mMediaPlayer.setLooping(false);//设置为循环播放
                mMediaPlayer.addMediaStateListener(new IMediaStateListener() {
                    @Override
                    public void onSeekComplete() {

                    }

                    @Override
                    public void onProgress(long progress, long total) {

                    }

                    @Override
                    public void onBufferingUpdate(int percent) {

                    }

                    @Override
                    public void onPlayerStateChanged(int state) {

                    }
                });
                //mMediaPlayer.prepare();//初始化播放器MediaPlayer
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        showStateView(TYPE_LOADING, false);
        newsListDataInvoker = new NewsListDataInvoker(this);
        recyclerAdapter.itemClickListener = this;
        recyclerAdapter.simpleBtmItemClickListener = this;
        refreshLayout.autoRefresh(5);
        if (retryTips != null) {
            retryTips.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!currentState.equals(TYPE_LOADING)) {
                        showStateView(TYPE_LOADING, false);
                        pageIndex = 1;
                        newsListDataInvoker.getContentListWithAd(catalogID, pageIndex, perPageSize, null);
                    }
                }
            });
        }
        if (loadingImage != null) {
            loadingImage.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!currentState.equals(TYPE_LOADING)) {
                        showStateView(TYPE_LOADING, false);
                        pageIndex = 1;
                        newsListDataInvoker.getContentListWithAd(catalogID, pageIndex, perPageSize, null);
                    }
                }
            });
        }
//        mSp = new SharedPreferencesCache(requireContext());
        View dialogView = View.inflate(requireContext(), R.layout.clock_in, null);
        View ViView = View.inflate(requireContext(), R.layout.clock_video, null);
        iamgeClose = ViView.findViewById(R.id.close);
        videoView = ViView.findViewById(R.id.videoview);
        ImageView close = dialogView.findViewById(R.id.close);
        close.setOnClickListener(v -> {
            mDialog.dismiss();
            if (mMediaPlayer != null) {
                mMediaPlayer.release();
            }
        });
        clockInLayout = dialogView.findViewById(R.id.clock_in_layout);
        clockedInLayout = dialogView.findViewById(R.id.clocked_in_layout);
        ImageView clockIn = dialogView.findViewById(R.id.clock_in);
        title = dialogView.findViewById(R.id.title);
        time = dialogView.findViewById(R.id.time);
        clockInDay = dialogView.findViewById(R.id.clock_in_day);
        clockInRank = dialogView.findViewById(R.id.clock_in_rank);
        ImageView clockInRankList = dialogView.findViewById(R.id.clock_in_rank_list);
        videoDialog = new Dialog(getContext(), R.style.CustomStyle);
        videoDialog.setContentView(ViView);
        videoDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, -1);
        clockIn.setOnClickListener(v -> {
            if (UserInfo.isLogin(requireContext())) {
                clockIn();
            } else {
                ToastUtil.show(requireContext(), "请先登录");
                LoginUtils.request_source = "爆料";
                LoginUtils.invokeLogin(requireContext());
            }
        });
        clockInRankList.setOnClickListener(v -> {
            Intent intent = new Intent(requireContext(), ClockInRankActivity.class);
            intent.putExtra("missionId", missionId);
            intent.putExtra("missionTitle", missionTitle);
            startActivity(intent);
        });
        ConstraintLayout contentLayout = dialogView.findViewById(R.id.content_layout);
        ViewGroup.LayoutParams lp = contentLayout.getLayoutParams();
        lp.width = (int) (DisplayUtils.INSTANCE.getScreenWidth(requireContext()) * 0.762);
        contentLayout.setLayoutParams(lp);

        mDialog = new AlertDialog.Builder(requireContext(), R.style.MyDialogStyle)
                .setView(dialogView)
                .create();
        new BindEventBus(this, adapter);

    }


    @Override
    public RecyclerView.LayoutManager getLayoutManager() {
        return ViewUtils.generateRecyclerLinearLayoutManager(getActivity(), true);
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        pageIndex++;
        newsListDataInvoker.getContentListWithAd(catalogID, pageIndex, pageIndex, null);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (adapter != null) {
            adapter.destroy();
        }
    }

    @Override
    public void onDestroy() {
        if (newsListDataInvoker != null)
            newsListDataInvoker.destory();
        super.onDestroy();
    }

    @Override
    public void onDetach() {
        super.onDetach();
        if (newsListDataInvoker != null)
            newsListDataInvoker.destory();
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        if (catalogItem != null && catalogItem.getCatalogStyle() == 1) {
            adapter.setNewsStyle(true);
        } else {
            adapter.setNewsStyle(false);
        }
       /* ArticleListDataWithAdv dataResult = CacheDataKt.readData(this, catalogID, ArticleListDataWithAdv.class);
        if (recyclerAdapter != null && recyclerAdapter.getItemCount() == 0 && dataResult != null && dataResult.articleList.size() > 0 && pageIndex  == 1) {
            success(dataResult);
            onlyRefresh = true;
        }*/
        pageIndex = 1;

        newsListDataInvoker.getContentListWithAd(catalogID, pageIndex, perPageSize, null);

    }

    private String ids = "";

    @Override
    public void success(ArticleListDataWithAdv data) {
        if (pageIndex == 1) {
            refreshLayout.finishRefresh();
           /* CacheDataKt.saveData(this, catalogID, data.orginData + "");
            if(onlyRefresh){//对比数据，
                Log.w(TAG,"this data only refresh");
                return;
            }*/
        }
        if (!data.more)
            refreshLayout.finishLoadMoreWithNoMoreData();
        else
            refreshLayout.finishLoadMore();
        JSONObject result = data.orginData.optJSONObject("data");
        if (pageIndex == 1) {
            if (FloatButtonGroup.haveFloatField(result)) {
                initFloatWin(result);
            } else {
                hideFloatWin();
            }
        }
        if (pageIndex == 1) {
            recyclerAdapter.getData().clear();
            //组件必须
            try {
                addComponent(data.componentItems);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        ids = "";
        for (int i = 0; i < data.articleList.size(); i++) {
            if (!TextUtils.isEmpty(ids)) {
                ids += "," + data.articleList.get(i).getId();
            } else {
                ids += data.articleList.get(i).getId();
            }
        }
        if (!TextUtils.isEmpty(ids)) {
            FacadeApi.getSpiderCmsApiJson(getActivity())
                    .getFaceData(ids, 5)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Observer<JSONObject>() {
                        @Override
                        public void onSubscribe(Disposable d) {

                        }

                        @Override
                        public void onNext(JSONObject jsonObject) {
                            if (jsonObject == null) {
                                return;
                            }
                            boolean state = jsonObject.optBoolean("state", false);
                            if (state) {
                                JSONArray meta = jsonObject.optJSONArray("data");
                                Set<String> blockList = BaoLiaoBlockListUtils.getUserBlockedList(getActivity());
                                //被屏蔽人列表
                                Set<String> blockPeopleList = BaoLiaoBlockListUtils.getUserBlockedPeopleList(getActivity());
                                for (ArticleItem articleItem : data.articleList) {
                                    if (articleItem.orginDataObject != null) {
                                        try {
                                            BaoNiaoListItem item = JSON.parseObject(articleItem.orginDataObject + "", BaoNiaoListItem.class);
                                            if (!blockList.contains(item.getId() + "") && !blockPeopleList.contains(item.getUid())) {
                                                for (int i = 0; i < meta.length(); i++) {
                                                    if (item.getId() == ((JSONObject) meta.get(i)).optLong("id")) {
                                                        item.setHitcount((int) ((JSONObject) meta.get(i)).optLong("hitCount"));
                                                        item.setCommentCount((int) ((JSONObject) meta.get(i)).optInt("commentCount"));
                                                        item.setFavorCount((int) ((JSONObject) meta.get(i)).optInt("supportCount"));
                                                        break;
                                                    }
                                                }
                                                recyclerAdapter.getData().add(item);
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }
                                int size = recyclerAdapter.getItemCount();
                                closeStateView();
                                if (pageIndex == 1) {
                                    recyclerView.notifyDataSetChanged();
                                } else {
                                    recyclerView.notifyItemRangeInserted(size, data.articleList.size());
                                }
                                data.articleList.clear();

                            }


                        }

                        @Override
                        public void onError(Throwable e) {
                            Set<String> blockList = BaoLiaoBlockListUtils.getUserBlockedList(getActivity());
                            //被屏蔽人列表
                            Set<String> blockPeopleList = BaoLiaoBlockListUtils.getUserBlockedPeopleList(getActivity());
                            for (ArticleItem articleItem : data.articleList) {
                                if (articleItem.orginDataObject != null) {
                                    try {
                                        BaoNiaoListItem item = JSON.parseObject(articleItem.orginDataObject + "", BaoNiaoListItem.class);
                                        if (!blockList.contains(item.getId() + "")
                                                && !blockPeopleList.contains(item.getUid())) {
                                            recyclerAdapter.getData().add(item);
                                        }
                                    } catch (Exception e1) {
                                        e1.printStackTrace();
                                    }
                                }
                            }
                            int size = recyclerAdapter.getItemCount();

                            if (pageIndex == 1 && recyclerAdapter.getData() != null && recyclerAdapter.getData().size() == 0 && data.componentItems.size() == 0) {
                                showStateView(TYPE_NO_CONTENT, false);
                            } else
                                closeStateView();
                            if (pageIndex == 1) {
                                recyclerView.notifyDataSetChanged();
                            } else {
                                recyclerView.notifyItemRangeInserted(size, data.articleList.size());
                            }
                            data.articleList.clear();
                        }

                        @Override
                        public void onComplete() {
                        }
                    });

        } else {
            Set<String> blockList = BaoLiaoBlockListUtils.getUserBlockedList(getActivity());
            //被屏蔽人列表
            Set<String> blockPeopleList = BaoLiaoBlockListUtils.getUserBlockedPeopleList(getActivity());
            for (ArticleItem articleItem : data.articleList) {
                if (articleItem.orginDataObject != null) {
                    try {
                        BaoNiaoListItem item = JSON.parseObject(articleItem.orginDataObject + "", BaoNiaoListItem.class);
                        if (!blockList.contains(item.getId() + "")
                                && !blockPeopleList.contains(item.getUid())) {
                            recyclerAdapter.getData().add(item);
                        }
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            }
            int size = recyclerAdapter.getItemCount();

            if (pageIndex == 1 && recyclerAdapter.getData() != null && recyclerAdapter.getData().size() == 0 && data.componentItems.size() == 0) {
                showStateView(TYPE_NO_CONTENT, false);
            } else
                closeStateView();
            if (pageIndex == 1) {
                recyclerView.notifyDataSetChanged();
            } else {
                recyclerView.notifyItemRangeInserted(size, data.articleList.size());
            }
            data.articleList.clear();
        }

    }

    @Override
    public void fault(Object data) {
        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();
        pageIndex -= 1;
        if (recyclerAdapter.getItemCount() == 0) {
            showStateView(TYPE_NO_CONTENT, false);
//            showStateView(TYPE_NET_NOT_GIVE_FORCE, false);
        } else {
            closeStateView();
        }
    }

    HistoryInvoker historyInvoker;

    @Override
    public void onItemClick(int index, boolean isFromAdaptor, BaseRecyclerAdapter adapter) {
       /* if (recyclerAdapter.getItem(index).getIs_display() == 0) {
            Log.w("APPTAG", "审核没过的  不能点");
            return;
        }*/

        Intent intent = new Intent(getActivity(), BaoLiaoDetailActivity.class);
        intent.putExtra("id", recyclerAdapter.getItem(index).getId());
        intent.putExtra("status", String.valueOf(recyclerAdapter.getItem(index).getStatusX()));
        intent.putExtra("url", recyclerAdapter.getItem(index).getShareHtml());
        startActivity(getActivity(), intent);
        if (recyclerAdapter != null) {
            recyclerAdapter.stopPlay();
        }
        if (historyInvoker == null) {
            historyInvoker = new HistoryInvoker();
        }
        if (UserInfo.getUserInfo(getContext()).isLogin()) {
            BaoNiaoListItem mod = recyclerAdapter.getItem(index);
            AddHistoryParamsData paramsData = new AddHistoryParamsData();
            paramsData.source = 19;
            paramsData.source_id = recyclerAdapter.getItem(index).getId();
            paramsData.summary = "";
            paramsData.title = mod.getTitle();
            paramsData.type = "19";
            paramsData.url = mod.getShareHtml();
            paramsData.logo = mod.getLogo();
//            paramsData.logoImgSize=mod.getLogoImgSize();
            historyInvoker.addHistory(UserInfo.getUserInfo(getContext()).getUserid(), paramsData, new HistoryInvoker.AddHistoryCallback() {
                @Override
                public void onSuccess() {
                    LogUtil.e("添加成功");
                }

                @Override
                public void onError() {

                }
            });
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void loginState(LoginEvent loginEvent) {
        f5();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void pauseVideo(OnPauseBaoliaoViedeoList pauseBaoliaoViedeoList) {
        if (recyclerAdapter != null) {
            recyclerAdapter.stopPlay();
        }
    }

    @Override
    public void itemClicked(int index, @NotNull Object tagData) {
        switch (index) {
            case 0:
                //屏蔽此人
//                ToastUtil.show(getActivity(), "屏蔽此人");
                if (recyclerAdapter.currentClickMorePosition > -1 && recyclerAdapter.currentClickMorePosition < recyclerAdapter.getItemCount()) {
                    String userId = "" + recyclerAdapter.getData().get(recyclerAdapter.currentClickMorePosition).getUid();
                    BaoLiaoBlockListUtils.addBlockPeople(getActivity(), userId);
                    removeDataByBlockPeople();
                }
                break;
            case 1:
                //不想看这条
                if (recyclerAdapter.currentClickMorePosition > -1 && recyclerAdapter.currentClickMorePosition < recyclerAdapter.getItemCount()) {
                    String id = "" + recyclerAdapter.getData().get(recyclerAdapter.currentClickMorePosition).getId();
                    BaoLiaoBlockListUtils.addUserBlockItem(getActivity(), id);
                    recyclerAdapter.getData().remove(recyclerAdapter.currentClickMorePosition);
                    recyclerView.notifyDataSetChanged();
                }
                break;
            case 2:
                //举报
                BaoLiaoItemMoreHandler.showReportDialog(getContext(), recyclerAdapter.getItem(recyclerAdapter.currentClickMorePosition).getUid(), getChildFragmentManager());
                break;
            default:
                break;
        }
    }

    //移除被屏蔽人的数据
    private void removeDataByBlockPeople() {
        Set<String> blockPeopleList = BaoLiaoBlockListUtils.getUserBlockedPeopleList(getActivity());
        List<BaoNiaoListItem> itemList = new ArrayList<>(recyclerAdapter.getData());
        for (BaoNiaoListItem baoNiaoListItem : itemList) {
            try {
                if (blockPeopleList.contains(baoNiaoListItem.getUid())) {
                    recyclerAdapter.getData().remove(baoNiaoListItem);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        recyclerView.notifyDataSetChanged();
    }


}